﻿//
//
// 版权所有 (c) 2021-2023 JR  
//
// 特此免费授予获得本软件的任何人以处理本软件的权利，但须遵守以下条件：在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
//
// 软件按“原样”提供，不提供任何形式的明示或暗示的保证，包括但不限于对适销性、适用性和非侵权的保证。
// 在任何情况下，作者或版权持有人均不对任何索赔、损害或其他责任负责，无论是因合同、侵权或其他方式引起的，与软件或其使用或其他交易有关。

using NewLife.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EMC.VISITOR.Plugin.GoView.Entity;
[SugarTable("GoViewPEConfig", "GoView 项目Echarts数据配置表")]
[SysTable]
public class GoViewProEchartsConfig : EntityTenant
{
    /// <summary>
    /// 关联项目Id
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "关联项目Id")]
    public long GoViewProId { get; set; }

    /// <summary>
    /// 大屏类型
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "大屏类型")]
    public BigScreenType? BigType { get; set; }
    [SugarColumn(ColumnDescription = "Echart图表配置", ColumnDataType = StaticConfig.CodeFirst_BigString)]
    public string Config { get; set; }

    [SugarColumn(IsIgnore = true)]
    public EchartOptions Option
    {
        get
        {
            return Config.IsNullOrEmpty() ? new EchartOptions() : JsonConvert.DeserializeObject<EchartOptions>(Config);
        }
        set
        {
            this.Config = (value != null ? JsonConvert.SerializeObject(value) : JsonConvert.SerializeObject(new EchartOptions()));
        }
    }
}

public class EchartOptions
{
    public static string defaultColor = "#fff"; //默认白色字体
    public static string xyDefaultColor = "#fff600"; // 默认黄色（x、y 轴线上的字体颜色）
    public EchartOptions()
    {
        tooltip = new tooltipModel();
        legend = new legendModel();
        color = new List<string>();
        xAxis = new List<XAxisModel>();
        yAxis = new List<YAxisModel>();
        series = new List<seriesModel>();
    }
    public tooltipModel tooltip { get; set; }
    public legendModel legend { get; set; }

    /// <summary>
    /// 柱子、线的颜色 
    /// </summary>
    public List<string> color { get; set; }

    public bool calculable { get; set; } = true;

    public List<XAxisModel> xAxis { get; set; }
    public List<YAxisModel> yAxis { get; set; }

    public List<seriesModel> series { get; set; }
    public class tooltipModel
    {
        public string trigger { get; set; } = "axis";
    }
    /// <summary>
    /// 图表上面显示的柱状图小标识
    /// </summary>
    public class legendModel
    {
        public legendModel()
        {
            data = new List<string>();
            textStyle = new textStyleModel();
        }
        /// <summary>
        /// 图表上面显示的柱状图小标识-名称
        /// </summary>
        public List<string> data { get; set; }

        public textStyleModel textStyle { get; set; }
        public class textStyleModel
        {
            public int fontSize { get; set; } = 15;
            /// <summary>
            /// 顶上图标字体的颜色(默认白色)
            /// </summary>
            public string color { get; set; } = EchartOptions.defaultColor;
        }
    }


    public class XY_AXISModel
    {
        public XY_AXISModel()
        {
            data = new List<dynamic>();
            axisLabel = new axisLabelModel();
        }
        public string type { get; set; }
        /// <summary>
        /// X轴刻度显示的值
        /// </summary>
        public virtual List<dynamic> data { get; set; }

        /// <summary>
        /// 是否显示轴刻度
        /// </summary>
        public bool show { get; set; } = true;
        public axisLabelModel axisLabel { get; set; }
        public class axisLabelModel
        {
            /// <summary>
            /// 轴字体大小
            /// </summary>
            public int fontSize { get; set; } = 15;
            /// <summary>
            /// 轴字体颜色
            /// </summary>
            public string color { get; set; } = EchartOptions.xyDefaultColor; //黄色
        }
    }

    public class XAxisModel : XY_AXISModel
    {

    }
    public class YAxisModel : XY_AXISModel
    {
        [JsonIgnore]
        public override List<dynamic> data { get => base.data; set => base.data = value; }
    }
    /// <summary>
    /// 轴或线的具体值
    /// </summary>
    public class seriesModel
    {
        public seriesModel()
        {
            data = new List<dynamic>();
            label = new labelModel();
        }
        /// <summary>
        /// 轴或线的名称（与legend data显示需一直）
        /// </summary>
        public string name { get; set; }
        public string type { get; set; }
        /// <summary>
        /// 轴或线的具体值
        /// </summary>
        public List<dynamic> data { get; set; }

        /// <summary>
        /// y轴索引???
        /// </summary>
        public int yAxisIndex { get; set; } = 1;
        public labelModel label { get; set; }
        public class labelModel
        {
            /// <summary>
            /// 是否在轴或线上显示数值
            /// </summary>
            public bool show { get; set; } = true;
            /// <summary>
            /// 显示数值的具体位置
            /// </summary>
            public string position { get; set; } = "top";

            public string color { get; set; } = EchartOptions.defaultColor;
        }
    }
}

